package com.rysm.wjsm.demo4;

import java.util.*;

public class MyRunnable implements Runnable {
    private int[] arr = {10,5,20,50,100,200,500,800,2,80,300,700};
    private int count = 12;
    private int count1 = 0;
    private int count2 = 0;
   private ArrayList<Integer> list1 = new ArrayList<>();
   private ArrayList<Integer> list2 = new ArrayList<>();
    Random r = new Random();
    @Override
    public void run() {
        while (true){
            synchronized (MyRunnable.class){
                if (count <= 0){
                    break;
                }else {
                    int i = r.nextInt(12);
                    if (Thread.currentThread().getName().equals("一号抽奖箱")){
                        list1.add(arr[i]);
                    }else{
                        list2.add(arr[i]);
                    }

                    System.out.println(i);
                    count--;
                }

            }
        }
        System.out.println(list1);
        System.out.println(list2);
//        Set<Map.Entry<String, Integer>> entries = map.entrySet();
//        for (Map.Entry<String, Integer> entry : entries) {
//            System.out.println(entry.getKey() + " " + entry.getValue());
//        }
//        Set<Map.Entry<String, Integer>> entries = map.entrySet();
//        for (Map.Entry<String, Integer> entry : entries) {
//            if (entry.getKey().equals("一号抽奖箱")){
//                count1++;
//            }else {
//                count2++;
//            }
//        }
//
//        for (Map.Entry<String, Integer> entry : entries) {
//            if (entry.getKey().equals("一号抽奖箱")){
//
//                list1.add(arr[entry.getValue()]);
//            }else {
//                list2.add(arr[entry.getValue()]);
//            }
//        }
        if (list1.size() != 0){
            int sum1 = 0;
        for (Integer integer : list1) {
           sum1 += integer;
      }
            int max1 = list1.get(0);
       for (Integer integer : list1) {
            if (max1 < integer){
                max1 = integer;
           }
       }
       System.out.println("在此次抽奖过程中，一号抽奖箱总共产生了" + list1.size() + "个奖项，分别为：" + list1 + "最高奖项为" + max1 + "元，总计额为" + sum1 + "元");
        }else {
            System.out.println("在此次抽奖过程中，一号抽奖箱总共产生了0个奖项");

        }
        if (list2.size() != 0){
            int sum2 = 0;
        for (Integer integer : list2) {
            sum2 += integer;
        }
            int max2 = list2.get(0);
        for (Integer integer : list2) {
            if (max2 < integer){
                max2 = integer;
            }
        }
                    System.out.println("在此次抽奖过程中，二号抽奖箱总共产生了" + list2.size() + "个奖项，分别为：" + list2 + "最高奖项为" + max2 + "元，总计额为" + sum2 + "元");
        }else{
            System.out.println("在此次抽奖过程中，二号抽奖箱总共产生了0个奖项");
        }
//        int sum1 = 0;
//        for (Integer integer : list1) {
//            sum1 += integer;
//        }
//        int sum2 = 0;
//        for (Integer integer : list2) {
//            sum2 += integer;
//        }
//        int max1 = list1.get(0);
//        for (Integer integer : list1) {
//            if (max1 < integer){
//                max1 = integer;
//            }
//        }
//        int max2 = list2.get(0);
//        for (Integer integer : list2) {
//            if (max2 < integer){
//                max2 = integer;
//            }
//        }
//        System.out.println("在此次抽奖过程中，一号抽奖箱总共产生了" + list1.size() + "个奖项，分别为：" + list1 + "最高奖项为" + max1 + "元，总计额为" + sum1 + "元");
//        System.out.println("在此次抽奖过程中，二号抽奖箱总共产生了" + list2.size() + "个奖项，分别为：" + list2 + "最高奖项为" + max2 + "元，总计额为" + sum2 + "元");
//

    }
}
